package com.hdl.controller;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.hdl.pojo.Article;
import com.hdl.service.ArticleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 类名 ArticleController
 * 描述 文章控制器接口类
 *
 * @author hedonglin
 * @version 1.0
 * @date 2020/5/19 11:04
 */
@Controller
public class IndexController {
    @Autowired
    private ArticleService articleService;

    @GetMapping("/")
    public String index(){
        return "redirect:/index";
    }

    @GetMapping("/index")
    public String list(Model model,
                       @RequestParam(defaultValue = "1") int pageNum,
                       @RequestParam(defaultValue = "3") int pageSize){
        // 开启pageHelper分页
        Page<Article> page = PageHelper.startPage(pageNum, pageSize);
        // 查询所有
        List<Article> articles = articleService.selectAll();
        model.addAttribute("page", page);
        model.addAttribute("articles", articles);
        return "client/index";
    }
}
